#include "t100.h"
#include "ctest.h"
#include "mem_tools.h"

CTEST(sram, width)
{
    uint32_t ret;

    ret = mem_mix_width_write_test(SRAM__BASE + 4000, SRAM__SIZE);
    ASSERT_TRUE(ret == SUCCESS);
}

static void SRAM_2_it_1(void)
{
    ASSERT_TRUE(SUCCESS);
}

CTEST(sram, zone)
{
    uint32_t ret;

    // Interrupt_register(HardFault_IRQn, SRAM_2_it_1);
    ret = mem_align_rw_test(SRAM__BASE, SRAM__SIZE);
    ASSERT_TRUE(ret == SUCCESS);
    ret = mem_align_rw_test(SRAM__BASE, SRAM__SIZE + 4);
    ASSERT_TRUE(SUCCESS);
}

static void SRAM_3_it_1(void)
{
    ASSERT_TRUE(SUCCESS);
}

CTEST(sram, zone_it)
{
    uint32_t ret;

    ret = mem_align_rw_test(SRAM__BASE, SRAM__SIZE);
    ASSERT_TRUE(ret == SUCCESS);

    // Interrupt_register(HardFault_IRQn, SRAM_3_it_1);
    ret = mem_align_rw_test(SRAM__BASE - 4, SRAM__SIZE);
    ASSERT_TRUE(SUCCESS);
}

CTEST(sram, align)
{
    uint32_t ret;

    ret = mem_unalign_rw_test(SRAM__BASE, SRAM__SIZE);
    ASSERT_TRUE(ret == SUCCESS);
}

CTEST(sram, march_c)
{
    uint32_t ret;

    ret = SRAM_MarchC_Aligned(SRAM__BASE, SRAM__SIZE);
    ASSERT_TRUE(ret == SUCCESS);
    ret = SRAM_MarchC_UnalignedStartAddr(SRAM__BASE, SRAM__SIZE);
    ASSERT_TRUE(ret == SUCCESS);
}

CTEST(sram, dma)
{
    memset((void *)SRAM__BASE, 0x55, SRAM__SIZE / 2);
    memset((void *)SRAM__BASE + SRAM__SIZE / 2, 0xAA, SRAM__SIZE / 2);
    
    DMA_memcpy((void *)SRAM__BASE + SRAM__SIZE / 2, (void *)SRAM__BASE + SRAM__SIZE / 2, SRAM__SIZE / 2);
    ASSERT_DATA((void *)SRAM__BASE + SRAM__SIZE / 2, SRAM__SIZE / 2, (void *)SRAM__BASE, SRAM__SIZE / 2);
}

CTEST(sram, step_9)
{
    uint32_t ret;

    ret = mem_9_step_test(SRAM__BASE,  SRAM__SIZE);
    ASSERT_TRUE(ret == SUCCESS);
}

